import { commodityStore } from '/@/store/locality/commodity';

export const commoditystore = commodityStore();

export function groupSku(data) {
  // 过滤最后一位
  const data1 = data.filter((item) => {
    if (item.skuName == '') console.log(item);
    else return item;
  });

  // const data1: any = data.splice(data.length - 1, 1); // 删除最后一个
  const SkuData: any = [];
  // console.log(123, data1);

  if (data1.length == 1) {
    data1[0].children.forEach((item, index) => {
      if (index == data1[0].children.length - 1) {
        index;
      } else
        SkuData.push({
          skuName: item.skuName,
          skuPrice: '',
          skuImage: '',
          skustockNum: '',
          skuintegral: '',
        });
    });
  } else if (data1.length == 2) {
    data1[0].children.forEach((item, index) => {
      data1[1].children.forEach((item1, index1) => {
        if (index == data1[0].children.length - 1 || index1 == data1[1].children.length - 1) {
          index;
        } else
          SkuData.push({
            skuName: item.skuName + '-' + item1.skuName,
            skuPrice: '',
            skuImage: '',
            skustockNum: '',
            skuintegral: '',
          });
      });
    });
  } else if (data1.length == 3) {
    data1[0].children.forEach((item, index) => {
      data1[1].children.forEach((item1, index1) => {
        data1[2].children.forEach((item2, index2) => {
          if (
            index == data1[0].children.length - 1 ||
            index1 == data1[1].children.length - 1 ||
            index2 == data1[2].children.length - 1
          ) {
            index;
          } else
            SkuData.push({
              skuName: item.skuName + '-' + item1.skuName + '-' + item2.skuName,
              skuPrice: '',
              skuImage: '',
              skustockNum: '',
              skuintegral: '',
            });
        });
      });
    });
  } else if (data1.length == 4) {
    data1[0].children.forEach((item, index) => {
      data1[1].children.forEach((item1, index1) => {
        data1[2].children.forEach((item2, index2) => {
          data1[3].children.forEach((item3, index3) => {
            if (
              index == data1[0].children.length - 1 ||
              index1 == data1[1].children.length - 1 ||
              index2 == data1[2].children.length - 1 ||
              index3 == data1[3].children.length - 1
            ) {
              index;
            } else
              SkuData.push({
                skuName:
                  item.skuName + '-' + item1.skuName + '-' + item2.skuName + '-' + item3.skuName,
                skuPrice: '',
                skuImage: '',
                skustockNum: '',
                skuintegral: '',
              });
          });
        });
      });
    });
  } else if (data1.length == 5) {
    data1[0].children.forEach((item, index) => {
      data1[1].children.forEach((item1, index1) => {
        data1[2].children.forEach((item2, index2) => {
          data1[3].children.forEach((item3, index3) => {
            data1[4].children.forEach((item4, index4) => {
              if (
                index == data1[0].children.length - 1 ||
                index1 == data1[1].children.length - 1 ||
                index2 == data1[2].children.length - 1 ||
                index3 == data1[3].children.length - 1 ||
                index4 == data1[4].children.length - 1
              ) {
                index;
              } else
                SkuData.push({
                  skuName:
                    item.skuName +
                    '-' +
                    item1.skuName +
                    '-' +
                    item2.skuName +
                    '-' +
                    item3.skuName +
                    '-' +
                    item4.skuName,
                  skuPrice: '',
                  skuImage: '',
                  skustockNum: '',
                  skuintegral: '',
                });
            });
          });
        });
      });
    });
  }
  console.log(SkuData);

  return SkuData;
}
